<template>
	<view class="Rsh">
		<u-navbar title="举报商品" :background="{ background: '#a0cfff' }" title-color="#FFFFFF"></u-navbar>
		<view class="u-m-30">
			<u-form :model="form" :rules="rules" ref="uForm" label-width="150">
				<u-form-item label="商品名">
					<u-input v-model="form.title" disabled />
				</u-form-item>
				<u-form-item label="举报类型">
					<u-input type="select" v-model="form.type" @click="typeClick()" />
				</u-form-item>
				<u-form-item label="举报描述">
					<u-input type="textarea" v-model="form.content" />
				</u-form-item>
			</u-form>
			<view class="u-m-t-30">
				<u-button type="error" @click="addReport()">确定</u-button>
			</view>
		</view>
		<u-select v-model="typeShow" :list="typeList" :default-value="typeDefault" @confirm="typeConfirm"></u-select>
	</view>
</template>

<script>
	import helper from '../../common/helper.js'
	export default {
		data() {
			return {
				form: {
					title: '',
					type: '',
					typeCode: '',
					content: '',
				},
				shopId: "",
				typeShow: false,
				typeDefault: [0],
				typeList: [{
						value: '1',
						label: '涉及黄色'
					},
					{
						value: '2',
						label: '商品假的'
					},
					{
						value: '3',
						label: '欺骗'
					}
				]
			}
		},
		onLoad: function(options) {
			let that = this
			if (options.id != "") {
				that.shopId = options.shopId
			}
			if (options.title != "") {
				that.form.title = options.title
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			typeClick() {
				this.typeShow = !this.typeShow
			},
			typeConfirm(e) {
				let that = this
				that.form.type = ""
				that.form.typeCode = ""
				e.map((val, index) => {
					that.form.type = val.label
					that.form.typeCode = val.value
					that.typeDefault = [index]
				})
			},
			addReport() {
				let that = this
				let user = uni.getStorageSync("user")
				if(that.form.type == ""){
					uni.showToast({
						title: '请选择举报类型',
						icon: 'none',
						duration: 2000
					})
					return
				}
				if(that.form.content == ""){
					uni.showToast({
						title: '请输入举报描述',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let data = {
					userId: user.id,
					shopId: that.shopId,
					reportType: that.form.typeCode,
					content: that.form.content
				}
				that.postRequest(helper.addReport, data).then(res => {
					if (res.data.flag == "200") {
						uni.showToast({
							title: '举报成功',
							icon: 'none',
							duration: 2000
						})
						that.form.type = ""
						that.form.typeCode = ""
						that.form.content = ""
					} else {
						uni.showToast({
							title: '举报失败',
							icon: 'none',
							duration: 2000
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
